<?php
require_once("includes/pagetop.php");
require_once("includes/common_snippets.php");

function downloadImageForUser($uid,$fileurl){
   	//header("Cache-Control: no-cache, must-revalidate");
	//$fileurl="http://mixednews.ru/wp-content/uploads/2011/10/0ed9320413f3ba172471860e77b15587.jpg";
	$filebasename= basename($fileurl);
	$filemimetype= getimagesize($fileurl); 
	//echo $filemimetype["mime"];
	//die();
	$fileToSend = $fileurl;
	// Set the headers, telling browsers that this is a JPEG image 
	//  and that it is called "myImage.jpg"
	header('Content-type: '.$filemimetype);
	header('Content-Disposition: attachment; filename="'.$filebasename.'"');
	 
	// Send along the file size, just to be thorough.
	//header("Content-Length: ". file_size($fileToSend));    	 
	// Send the contents of the file
	readfile($fileToSend);
}

//$filep=urlencode("http://logic4soft.com/allyfolio/uploads/post_media/5/nicola_peltz_in_transformers_age_of_extinction-wide.jpeg");
//$filePath=urldecode($filep);
//downloadImageForUser(1,$filePath);

if(isset($_REQUEST["filepathdownload"])&& strlen(trim($_REQUEST["filepathdownload"]))>0){
    $relpath=getScriptLocatedAbsolutePath();
    $filePath=$relpath.urldecode($_REQUEST["filepathdownload"]);
    //echo $filePath;
    downloadImageForUser(1,$filePath);        
}



?>